<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all" />
    <style>
      .layui-form-item .layui-input-inline {
        width: 150px;
      }
      .layui-form-label {
        padding: 9px 5px;
        width: auto;
      }
    </style>
  </head>
  <body>
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
          <ul class="layui-tab-title layui_tab_title">
            <li>
              <a href="{:url('video/replay_category')}">一级分类</a>
            </li>
            <li class="layui-this">
              <a href="{:url('video/replay_child_category_list')}">二级分类</a>
            </li>
          </ul>
        </div>
        <form class="layui-form" action=""  id="sbumitForm">
          <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
              <div class="layui-inline">
                <div class="layui-btn" onclick="add()">新建分类</div>
              </div>
              <div class="layui-inline">
                <select name="category" id="category" lay-filter="category">
                  <option value="">全部</option>
                  <?php foreach($replay_categorys as $key => $value) { ?></php>
                  <option value="{$key}">{$value}</option>
                  <?php }?>
                </select>
              </div>
              <div class="layui-inline">
                <div class="layui-btn" id="FormSubmit">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </div>
              </div>
            </div>
          </div>
        </form>
        <div class="layui-card-body">
          <table id="demo" lay-filter="test"></table>
        </div>
      </div>
    </div>
    <script src="/layuiadmin/layui/layui.js"></script>
    <script>
      layui
        .config({
          base: "/layuiadmin/", //静态资源所在路径
        })
        .extend({
          index: "lib/index", //主入口模块
        })
        .use(["table", "form"], function () {
          ($ = layui.jquery), (table = layui.table), (form = layui.form);
          table.render(table_conf());
          $("#FormSubmit").click(function () {
              table.render(table_conf());
          });
        });
        function table_conf() {
          return {
            elem: "#demo",
            id: "#demo",
            url: "/admin/video/replay_child_category_list?"+ $("#sbumitForm").serialize(),
            defaultToolbar: [
              "filter",
              "print",
              {
                title: "提示",
                layEvent: "LAYTABLE_EXCEL",
                icon: "layui-icon-table",
              },
            ],
            page: {
              curr: 1, //默认从第一页开始搜索
            },
            method: "get",
            //where: $("#sbumitForm").serialize(),
            limit: 20,
            limits: [20, 30, 50, 100, 200],
            text: {
              none: "暂无相关数据！", //默认无数据
            },
            response: {
              statusName: "code",
              statusCode: 0,
              msgName: "msg",
              countName: "count",
              dataName: "list",
            },
            cols: [
              [
                //表头
                { field: "id", title: "序号", width: "10%", align: "center" },
                { field: "sort", title: "排序", width: "15%", align: "center" },
                {
                  field: "name",
                  title: "回放分类",
                  width: "15%",
                  align: "center",
                },
                {
                  field: "create_time",
                  title: "添加时间",
                  width: "18%",
                  align: "center",
                },
                {
                  field: "operator",
                  title: "操作人",
                  width: "18%",
                  align: "center",
                  templet: function (item) {
                    if (item.operator) {
                      return item.operator;
                    }

                    return "-";
                  },
                },
                {
                  title: "操作",
                  align: "center",
                  templet: function (item) {
                    html =
                      '<a class="layui-btn  layui-btn-xs" onclick="edit(' +
                      item["id"] +
                      ')"><i class="layui-icon"></i>编辑</a>';
                    if (item.status == 0) {
                      html +=
                        '<a class="layui-btn  layui-btn-xs"  onclick="status(' +
                        item["id"] +
                        ', 1)" style="background-color: #1E9FFF" ><i class="layui-icon"></i>显示</a>';
                    } else {
                      html +=
                        '<a class="layui-btn  layui-btn-xs"  onclick="status(' +
                        item["id"] +
                        ', 0)" style="background-color: #db0b25"><i class="layui-icon"></i>隐藏</a>';
                    }
                    return html;
                  },
                },
              ],
            ],
            done: function (res, curr, count) {
              res.list.forEach(function (item, index) {});
            },
          }
        }

      function status(id, status) {
        var title = "隐藏吗？";
        if (status == 1) {
          title = "显示吗？";
        }
        layer.confirm("确认要" + title, { icon: 6 }, function () {
          $.ajax({
            type: "POST", //请求方式
            url: "/admin/video/replay_category_status", //请求地址
            dataType: "json", //返回的数据类型
            data: { id: id, status: status }, //数据
            //请求成功
            success: function (data) {
              if (data.code == 0) {
                layer.msg(data.msg, { icon: 1, time: 2000 }, function () {
                  window.location.reload();
                });
              } else {
                layer.msg(data.msg, { icon: 2, time: 5000 });
              }
            },
          });
        });
      }

      function edit(id) {
        layer.open({
          type: 2,
          title: ["编辑", "font-size:16px"],
          content: "/admin/video/replay_child_category_edit?id=" + id,
          area: ["500px", "300px"],
          //offset: '0px',
        });
      }

      function add() {
        layer.open({
          type: 2,
          title: ["添加", "font-size:16px"],
          content: "/admin/video/add_replay_category",
          area: ["500px", "300px"],
          //offset: '0px',
        });
      }
    </script>
  </body>
</html>
